package com.ziyun.erp.web.modules.business.controller;

import com.ziyun.erp.modules.business.entity.BusinessMessagePeopleEntity;
import com.ziyun.erp.modules.business.service.BusinessMessagePeopleService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;


/**
 * 营销短信人群表
 *
 * @author
 * @email
 * @date 2018-08-21 15:11:42
 */
@RestController
@RequestMapping("business/businessmessagepeople")
public class BusinessMessagePeopleController {
    @Autowired
    private BusinessMessagePeopleService businessMessagePeopleService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:businessmessagepeople:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = businessMessagePeopleService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:businessmessagepeople:info")
    public R info(@PathVariable("id") Integer id) {
        BusinessMessagePeopleEntity businessMessagePeople = businessMessagePeopleService.selectById(id);

        return R.ok().put("businessMessagePeople", businessMessagePeople);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:businessmessagepeople:save")
    public R save(@RequestBody BusinessMessagePeopleEntity businessMessagePeople) {
        businessMessagePeopleService.insert(businessMessagePeople);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:businessmessagepeople:update")
    public R update(BusinessMessagePeopleEntity businessMessagePeople) {
        ValidatorUtils.validateEntity(businessMessagePeople);
        businessMessagePeopleService.updateById(businessMessagePeople);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:businessmessagepeople:delete")
    public R delete(@RequestBody Integer[] ids) {
        businessMessagePeopleService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
